import React, {useState} from "react";
import {ObjInfo} from "@/api/Types/ObjInterfaces.ts";
import {createStyles} from "antd-style";
import ObjApi from "@/api/ObjApi.ts";
import {Button} from "antd";
import {DownOutlined} from "@ant-design/icons";

const useStyles = createStyles(({css, token}) => {
    return {
        container: css`
            width: 100vw;
            height: 200px;
            position: fixed;
            left: 0;
            bottom: 10%;
            padding: 0 4vw;

            ul {
                display: flex;
                overflow: auto hidden;
                transition: all .2s ease-in-out;

                :hover::-webkit-scrollbar {
                    height: 8px;
                }

                ::-webkit-scrollbar {
                    height: 0;
                    transition: height .2s ease-in-out;
                }

                ::-webkit-scrollbar-track {
                    background: rgba(0, 0, 0, .1); /* 轨道背景颜色 */
                }

                ::-webkit-scrollbar-thumb {
                    background: rgba(120, 120, 120); /* 滑块背景颜色 */
                }

                ::-webkit-scrollbar-thumb:hover {
                    background: rgb(150, 150, 150); /* 鼠标悬停在滑块上时的背景颜色 */
                }

                li {
                    overflow: hidden;

                    button {
                        display: block;
                        background-color: transparent;
                        width: auto;
                        height: 200px;
                        transition: all .2s ease-in-out;
                        border: 0;
                        padding: 0;
                        position: relative;

                        :hover {
                            transform: scale(1.2);

                            h3 {
                                opacity: 0;
                            }

                            img {
                                opacity: 100%;
                            }
                        }
                    }

                    h3 {
                        transition: all .2s ease-in-out;
                        opacity: 100%;
                    }

                    img {
                        transition: all .2s ease-in-out;
                        opacity: 0;
                        position: absolute;
                        left: 0;
                        top: 0;
                        width: 100%;
                        height: 100%;
                        object-fit: cover;
                        object-position: center;
                        z-index: -1;
                    }
                }
            }
        `,
    }
})

interface Props {
    objInfoList: ObjInfo[],
    setObjInfo: (objInfo: ObjInfo) => void
}

const SceneSelector: React.FC<Props> = ({objInfoList, setObjInfo}) => {
    const styles = useStyles().styles;

    return (
        <div className={styles.container}>
            <ul>
                {
                    objInfoList.map(item => {
                        return (
                            <li
                                key={item.id}
                            >
                                <button onClick={() => {
                                    setObjInfo(item)
                                }}>
                                    <img src={ObjApi.getObjLink(item.objLink)}
                                         alt={item.objName}
                                    />
                                    <h3>{item.objName}</h3>
                                </button>
                            </li>
                        )
                    })
                }
            </ul>
        </div>
    )
}

export default SceneSelector